/*
 * author zby
 * 首页初始化数据
 */

(function (document, window, $, Utils) {
    'use strict';
    var vm = {};
    $(function () {
        var fns = {
            search: function (me) {
                Utils.getSimpleJson({
                    url: "/core/systemRecord/page",
                    params: Utils.getSearchParams(me),
                    fn: function (data) {
                        vm.systems = data;
                    }
                })
            },
            change: function (me) {
                const id = $(me).find("option:selected").val();
                if (id) {
                    vm.proName = $(me).find("option:selected").text()
                } else {
                    vm.proName = "全部省份"
                }
            },
            export: function (me) {
                let ctype = $(me).attr("ctype");
                var params = {};
                params.exportType = ctype;
                if (ctype == 'exportCurrent') {
                    const forms = $(me).parents("h3").next()
                    $(forms).each(function () {
                        let val = $(this).is("input") ? ($(this).val()) : ($(this).find("option:selected").val());
                        params[$(this).attr("cname")] = val;
                    })
                }
                const url = "/core/systemRecord/export";
                window.open(constant.server_path + url + "?" + Utils.formatParams(params));
            }
        };
        window.fns = fns;
        init();
    });

    //入口方法
    function init() {
        vm = new Vue({
            el: '#tableInfo',
            data: {
                systems: {},
                proName: "全部省份",
                provinces: ""
            },
        })
        Utils.getSimpleJson({
            url: "/core/area/list",
            fn: function (data) {
                vm.provinces = data;
            }
        })
        Utils.getSimpleJson({
            url: "/core/enum/list",
            params: {
                path: "ResultTypeEnum,FileTypeEnum,DownloadOrUploadEnum,PersonTypeEnum",
            },
            fn: function (data) {
                vm.enums = data;
            }
        })
        fns.search();
    }


})(document, window, jQuery, Utils);